package com.example.show_auto.utils

import com.example.show_auto.data.Chef
import com.example.show_auto.data.Equip
import com.example.show_auto.data.GameData
import com.example.show_auto.data.Skill
import com.example.show_auto.ui.pages.UltimateSkillsState

/**
 * 厨师技法计算器
 * 负责应用个人技法加成和厨具技能加成到厨师基础技法上
 * 对应web项目中的setDataForChef功能
 */
object ChefSkillCalculator {
    
    /**
     * 应用个人技法加成和厨具技能加成到厨师上
     * @param chef 原始厨师数据
     * @param ultimateSkills 个人技法加成数据
     * @param equip 厨具数据（可选）
     * @param skills 技能数据列表
     * @param chefInteractionBonus 厨师间技法影响加成（可选）
     * @return 应用加成后的厨师数据副本
     */
    fun applyAllSkills(
        chef: Chef,
        ultimateSkills: UltimateSkillsState,
        equip: Equip? = null,
        skills: List<Skill> = emptyList(),
        chefInteractionBonus: Map<String, Int>? = null,
        useAllUltimateTraining: Boolean = false
    ): Chef {
        // 创建厨师副本，避免修改原始数据
        val enhancedChef = chef.copy()
        
        // 1. 应用个人技法加成
        enhancedChef.stirfry += ultimateSkills.stirfry
        enhancedChef.boil += ultimateSkills.boil
        enhancedChef.knife += ultimateSkills.knife
        enhancedChef.fry += ultimateSkills.fry
        enhancedChef.bake += ultimateSkills.bake
        enhancedChef.steam += ultimateSkills.steam
        
        // 2. 应用性别特定的全技法加成
        if (isChefMale(chef)) {
            // 男厨师应用男厨全技法加成
            enhancedChef.stirfry += ultimateSkills.maleAllSkill
            enhancedChef.boil += ultimateSkills.maleAllSkill
            enhancedChef.knife += ultimateSkills.maleAllSkill
            enhancedChef.fry += ultimateSkills.maleAllSkill
            enhancedChef.bake += ultimateSkills.maleAllSkill
            enhancedChef.steam += ultimateSkills.maleAllSkill
        } else {
            // 女厨师应用女厨全技法加成
            enhancedChef.stirfry += ultimateSkills.femaleAllSkill
            enhancedChef.boil += ultimateSkills.femaleAllSkill
            enhancedChef.knife += ultimateSkills.femaleAllSkill
            enhancedChef.fry += ultimateSkills.femaleAllSkill
            enhancedChef.bake += ultimateSkills.femaleAllSkill
            enhancedChef.steam += ultimateSkills.femaleAllSkill
        }
        
        // 3. 应用厨具技能加成
        if (equip != null) {
            applyEquipSkills(enhancedChef, equip, skills, chef, useAllUltimateTraining)
        }

        // 4. 应用厨师间技法影响加成
        if (chefInteractionBonus != null) {
            enhancedChef.stirfry += chefInteractionBonus["stirfry"] ?: 0
            enhancedChef.boil += chefInteractionBonus["boil"] ?: 0
            enhancedChef.knife += chefInteractionBonus["knife"] ?: 0
            enhancedChef.fry += chefInteractionBonus["fry"] ?: 0
            enhancedChef.bake += chefInteractionBonus["bake"] ?: 0
            enhancedChef.steam += chefInteractionBonus["steam"] ?: 0
        }

        // 5. 应用厨师自身技能的百分比加成（普通技能和修炼技能）
        if (chef.skill > 0 || (chef.ult && chef.hasUltimateSkill())) {
            applyChefPercentageSkills(enhancedChef, chef, skills, useAllUltimateTraining)
        }

        return enhancedChef
    }
    
    /**
     * 判断厨师性别
     * 根据厨师的tags字段判断性别
     * @param chef 厨师数据
     * @return true表示男性，false表示女性
     */
    private fun isChefMale(chef: Chef): Boolean {
        // 根据游戏数据，tags中包含1表示男性，包含2表示女性
        // 如果没有tags信息，默认按名字或其他规则判断
        return when {
            chef.tags.contains(1) -> true  // 男性标签
            chef.tags.contains(2) -> false // 女性标签
            else -> {
                // 如果没有明确的性别标签，可以根据名字或其他规则判断
                // 这里简化处理，默认为男性
                true
            }
        }
    }
    
    /**
     * 应用厨具技能加成到厨师上
     * @param chef 要应用加成的厨师
     * @param equip 厨具数据
     * @param skills 技能数据列表
     * @param originalChef 原始厨师数据（用于计算厨具技能效果翻倍）
     * @param useAllUltimateTraining 是否启用默认全修炼
     */
    private fun applyEquipSkills(chef: Chef, equip: Equip, skills: List<Skill>, originalChef: Chef, useAllUltimateTraining: Boolean = false) {
        // 检查厨师是否有厨具技能效果翻倍的修炼技能
        val hasEquipSkillMultiplier = hasEquipSkillMultiplier(originalChef, skills, useAllUltimateTraining)
        val multiplier = if (hasEquipSkillMultiplier) 2.0 else 1.0
        
        // 遍历厨具的所有技能
        for (skillId in equip.skill) {
            val skill = skills.find { it.skillId == skillId }
            skill?.let { applyEquipSkill(chef, it, multiplier) }
        }
    }
    
    /**
     * 应用单个厨具技能效果（支持复杂技能描述）
     * @param chef 要应用加成的厨师
     * @param skill 技能数据
     * @param multiplier 技能效果倍数（厨具技能效果翻倍时为2.0）
     */
    private fun applyEquipSkill(chef: Chef, skill: Skill, multiplier: Double) {
        // 解析技能描述来确定技能类型和数值
        val skillDesc = skill.desc

        // 处理全技法（优先处理，避免与单项技法冲突）
        if (skillDesc.contains("全技法")) {
            val value = extractSkillValueForType(skillDesc, "全技法")
            val intValue = (value * multiplier).toInt()
            chef.stirfry += intValue
            chef.boil += intValue
            chef.knife += intValue
            chef.fry += intValue
            chef.bake += intValue
            chef.steam += intValue
            return // 全技法处理完毕，不再处理单项技法
        }

        // 处理复合技法（如"炸与炒技法+120"）
        val compoundSkillValue = extractCompoundSkillValue(skillDesc)
        if (compoundSkillValue > 0) {
            val intValue = (compoundSkillValue * multiplier).toInt()
            val affectedSkills = parseCompoundSkillTypes(skillDesc)
            for (skillType in affectedSkills) {
                when (skillType) {
                    "炒" -> chef.stirfry += intValue
                    "煮" -> chef.boil += intValue
                    "切" -> chef.knife += intValue
                    "炸" -> chef.fry += intValue
                    "烤" -> chef.bake += intValue
                    "蒸" -> chef.steam += intValue
                }
            }
            return // 复合技法处理完毕，不再处理单项技法
        }

        // 处理各项单独技法（支持复合技法描述）
        val skillTypes = mapOf(
            "炒技法" to { value: Int -> chef.stirfry += value },
            "煮技法" to { value: Int -> chef.boil += value },
            "切技法" to { value: Int -> chef.knife += value },
            "炸技法" to { value: Int -> chef.fry += value },
            "烤技法" to { value: Int -> chef.bake += value },
            "蒸技法" to { value: Int -> chef.steam += value }
        )

        // 遍历所有技法类型，查找并应用技法加成
        for ((skillType, applyFunction) in skillTypes) {
            if (skillDesc.contains(skillType)) {
                val value = extractSkillValueForType(skillDesc, skillType)
                if (value != 0) {
                    val intValue = (value * multiplier).toInt()
                    applyFunction(intValue)
                }
            }
        }
    }
    
    /**
     * 从技能描述中提取数值（包含正负号）
     * 例如："炒技法+100" -> 100, "蒸技法-200" -> -200
     */
    private fun extractSkillValue(skillDesc: String): Int {
        val regex = Regex("([+\\-]?\\d+)")
        val matchResult = regex.find(skillDesc)
        return matchResult?.groupValues?.get(1)?.toIntOrNull() ?: 0
    }

    /**
     * 从技能描述中提取特定技法类型的数值
     * 例如："蒸技法+200 烤技法-50 煮技法-50" + "烤技法" -> -50
     */
    private fun extractSkillValueForType(skillDesc: String, skillType: String): Int {
        // 构建正则表达式来匹配特定技法类型的数值
        val regex = Regex("${skillType}([+\\-]?\\d+)")
        val matchResult = regex.find(skillDesc)
        return matchResult?.groupValues?.get(1)?.toIntOrNull() ?: 0
    }
    
    /**
     * 检查厨师是否有厨具技能效果翻倍的修炼技能
     * @param chef 厨师数据
     * @param skills 技能数据列表
     * @param useAllUltimateTraining 是否启用默认全修炼
     * @return true表示有厨具技能效果翻倍
     */
    private fun hasEquipSkillMultiplier(chef: Chef, skills: List<Skill>, useAllUltimateTraining: Boolean = false): Boolean {
        // 检查厨师是否应该应用修炼技能：默认全修炼开启 或 (已拥有且已修炼)
        val shouldApplyUltimateSkills = if (useAllUltimateTraining) {
            true // 默认全修炼时，所有厨师都视为已修炼
        } else {
            chef.got && chef.ult // 只有已拥有且已修炼的厨师才有修炼技能效果
        }
        
        if (!shouldApplyUltimateSkills) return false
        if (!chef.hasUltimateSkill()) return false
        for (skillId in chef.getAllUltimateSkills()) {
            val ultimateSkill = skills.find { it.skillId == skillId }
            if (ultimateSkill?.desc?.contains("厨具技能效果翻倍") == true) return true
        }
        return false
    }
    
    /**
     * 兼容旧方法：只应用个人技法加成
     */
    fun applyUltimateSkills(chef: Chef, ultimateSkills: UltimateSkillsState): Chef {
        return applyAllSkills(chef, ultimateSkills, null, emptyList())
    }
    
    /**
     * 获取厨师的技法显示文本（包含所有加成）
     */
    fun getEnhancedSkillText(
        chef: Chef, 
        ultimateSkills: UltimateSkillsState, 
        equip: Equip? = null, 
        skills: List<Skill> = emptyList()
    ): String {
        val enhancedChef = applyAllSkills(chef, ultimateSkills, equip, skills)
        return buildString {
            append("炒${enhancedChef.stirfry} ")
            append("煮${enhancedChef.boil} ")
            append("切${enhancedChef.knife}")
        }
    }
    
    /**
     * 获取厨师的第二行技法显示文本（包含所有加成）
     */
    fun getEnhancedSkillText2(
        chef: Chef, 
        ultimateSkills: UltimateSkillsState, 
        equip: Equip? = null, 
        skills: List<Skill> = emptyList()
    ): String {
        val enhancedChef = applyAllSkills(chef, ultimateSkills, equip, skills)
        return buildString {
            append("炸${enhancedChef.fry} ")
            append("烤${enhancedChef.bake} ")
            append("蒸${enhancedChef.steam}")
        }
    }
    
    /**
     * 获取厨师的紧凑技法显示文本（用于小空间显示，包含所有加成）
     */
    fun getCompactEnhancedSkillText(
        chef: Chef,
        ultimateSkills: UltimateSkillsState,
        equip: Equip? = null,
        skills: List<Skill> = emptyList(),
        chefInteractionBonus: Map<String, Int>? = null
    ): String {
        val enhancedChef = applyAllSkills(chef, ultimateSkills, equip, skills, chefInteractionBonus)
        return buildString {
            append("炒${enhancedChef.stirfry.toString().padStart(3)} ")
            append("煮${enhancedChef.boil.toString().padStart(3)} ")
            append("切${enhancedChef.knife.toString().padStart(3)}")
        }
    }
    
    /**
     * 获取厨师的第二行紧凑技法显示文本（包含所有加成）
     */
    fun getCompactEnhancedSkillText2(
        chef: Chef,
        ultimateSkills: UltimateSkillsState,
        equip: Equip? = null,
        skills: List<Skill> = emptyList(),
        chefInteractionBonus: Map<String, Int>? = null
    ): String {
        val enhancedChef = applyAllSkills(chef, ultimateSkills, equip, skills, chefInteractionBonus)
        return buildString {
            append("炸${enhancedChef.fry.toString().padStart(3)} ")
            append("烤${enhancedChef.bake.toString().padStart(3)} ")
            append("蒸${enhancedChef.steam.toString().padStart(3)}")
        }
    }
    
    /**
     * 检查是否有任何技法加成（个人技法、厨具技能或厨师间影响）
     */
    fun hasAnySkillBonus(
        ultimateSkills: UltimateSkillsState,
        equip: Equip? = null,
        chefInteractionBonus: Map<String, Int>? = null
    ): Boolean {
        val hasUltimateSkills = ultimateSkills.stirfry > 0 ||
                ultimateSkills.boil > 0 ||
                ultimateSkills.knife > 0 ||
                ultimateSkills.fry > 0 ||
                ultimateSkills.bake > 0 ||
                ultimateSkills.steam > 0 ||
                ultimateSkills.maleAllSkill > 0 ||
                ultimateSkills.femaleAllSkill > 0

        val hasEquipSkills = equip?.skill?.isNotEmpty() == true

        val hasInteractionBonus = chefInteractionBonus?.values?.any { it != 0 } ?: false

        return hasUltimateSkills || hasEquipSkills || hasInteractionBonus
    }

    /**
     * 检查是否有厨具技能加成
     */
    fun hasEquipSkillBonus(equip: Equip?): Boolean {
        return equip?.skill?.isNotEmpty() == true
    }

    /**
     * 检查是否有厨师间技法影响
     */
    fun hasChefInteractionBonus(chefInteractionBonus: Map<String, Int>?): Boolean {
        return chefInteractionBonus?.values?.any { it != 0 } ?: false
    }

    /**
     * 检查特定技法是否受到厨师间技法影响
     */
    fun hasSpecificChefInteractionBonus(chefInteractionBonus: Map<String, Int>?, skillType: String): Boolean {
        return chefInteractionBonus?.get(skillType) ?: 0 > 0
    }

    /**
     * 检查特定技法是否受到厨具技能影响
     */
    fun hasSpecificEquipSkillBonus(chef: Chef, equip: Equip?, skills: List<Skill>, skillType: String): Boolean {
        if (equip?.skill?.isEmpty() != false) return false

        // 检查厨具的所有技能是否影响指定技法
        for (skillId in equip.skill) {
            val equipSkill = skills.find { it.skillId == skillId }
            if (equipSkill != null) {
                val description = equipSkill.desc
                
                // 检查复合技法是否影响指定技法
                val compoundSkillTypes = parseCompoundSkillTypes(description)
                val skillTypeInChinese = when (skillType) {
                    "stirfry" -> "炒"
                    "boil" -> "煮"
                    "knife" -> "切"
                    "fry" -> "炸"
                    "bake" -> "烤"
                    "steam" -> "蒸"
                    else -> ""
                }
                
                if (compoundSkillTypes.contains(skillTypeInChinese)) {
                    return true
                }
                
                // 原有的单项技法检查
                val affectsSkill = when (skillType) {
                    "stirfry" -> description.contains("炒") && (description.contains("技法") || description.contains("技能"))
                    "boil" -> description.contains("煮") && (description.contains("技法") || description.contains("技能"))
                    "knife" -> description.contains("切") && (description.contains("技法") || description.contains("技能"))
                    "fry" -> description.contains("炸") && (description.contains("技法") || description.contains("技能"))
                    "bake" -> description.contains("烤") && (description.contains("技法") || description.contains("技能"))
                    "steam" -> description.contains("蒸") && (description.contains("技法") || description.contains("技能"))
                    else -> false
                } || description.contains("全技法") || description.contains("所有技法")

                if (affectsSkill) return true
            }
        }
        return false
    }
    
    /**
     * 检查是否有个人技法加成
     */
    fun hasUltimateSkills(ultimateSkills: UltimateSkillsState): Boolean {
        return ultimateSkills.stirfry > 0 ||
                ultimateSkills.boil > 0 ||
                ultimateSkills.knife > 0 ||
                ultimateSkills.fry > 0 ||
                ultimateSkills.bake > 0 ||
                ultimateSkills.steam > 0 ||
                ultimateSkills.maleAllSkill > 0 ||
                ultimateSkills.femaleAllSkill > 0
    }

    /**
     * 只应用个人技法加成（用于厨具推荐）
     * @param chef 原始厨师数据
     * @param ultimateSkills 个人技法状态
     * @param skills 技能列表
     * @param useAllUltimateTraining 是否启用默认全修炼
     * @return 应用个人技法加成后的厨师数据
     */
    fun applyPersonalSkills(
        chef: Chef,
        ultimateSkills: UltimateSkillsState,
        skills: List<Skill>,
        useAllUltimateTraining: Boolean = false
    ): Chef {
        // 创建厨师副本，避免修改原始数据
        val enhancedChef = chef.copy()

        // 1. 应用个人技法加成
        enhancedChef.stirfry += ultimateSkills.stirfry
        enhancedChef.boil += ultimateSkills.boil
        enhancedChef.knife += ultimateSkills.knife
        enhancedChef.fry += ultimateSkills.fry
        enhancedChef.bake += ultimateSkills.bake
        enhancedChef.steam += ultimateSkills.steam

        // 2. 应用性别特定的全技法加成
        if (isChefMale(chef)) {
            // 男厨师应用男厨全技法加成
            enhancedChef.stirfry += ultimateSkills.maleAllSkill
            enhancedChef.boil += ultimateSkills.maleAllSkill
            enhancedChef.knife += ultimateSkills.maleAllSkill
            enhancedChef.fry += ultimateSkills.maleAllSkill
            enhancedChef.bake += ultimateSkills.maleAllSkill
            enhancedChef.steam += ultimateSkills.maleAllSkill
        } else {
            // 女厨师应用女厨全技法加成
            enhancedChef.stirfry += ultimateSkills.femaleAllSkill
            enhancedChef.boil += ultimateSkills.femaleAllSkill
            enhancedChef.knife += ultimateSkills.femaleAllSkill
            enhancedChef.fry += ultimateSkills.femaleAllSkill
            enhancedChef.bake += ultimateSkills.femaleAllSkill
            enhancedChef.steam += ultimateSkills.femaleAllSkill
        }

        // 3. 应用厨师自身技能的百分比加成（普通技能和修炼技能）
        // 注意：这里会调用applyChefPercentageSkills，其中已经包含了状态检查逻辑
        if (chef.skill > 0 || (chef.ult && chef.hasUltimateSkill())) {
            applyChefPercentageSkills(enhancedChef, chef, skills, useAllUltimateTraining)
        }

        return enhancedChef
    }

    /**
     * 只应用厨具技法加成（用于厨具推荐）
     * @param chef 厨师数据（可能已应用个人技法加成）
     * @param equip 厨具
     * @param skills 技能列表
     * @param useAllUltimateTraining 是否启用默认全修炼
     * @return 应用厨具技法加成后的厨师数据
     */
    fun applyEquipSkills(
        chef: Chef,
        equip: Equip,
        skills: List<Skill>,
        useAllUltimateTraining: Boolean = false
    ): Chef {
        // 创建厨师副本，避免修改原始数据
        val enhancedChef = chef.copy()

        // 应用厨具技能加成（使用新的数据结构）
        applyEquipSkills(enhancedChef, equip, skills, chef, useAllUltimateTraining)

        return enhancedChef
    }
    
    /**
     * 应用厨师自身技能的百分比加成（普通技能和修炼技能）
     * @param chef 要应用加成的厨师（已应用其他加成）
     * @param originalChef 原始厨师数据（用于获取技能信息）
     * @param skills 技能数据列表
     * @param useAllUltimateTraining 是否启用默认全修炼
     */
    private fun applyChefPercentageSkills(chef: Chef, originalChef: Chef, skills: List<Skill>, useAllUltimateTraining: Boolean = false) {
        // 1. 处理厨师的普通技能
        if (originalChef.skill > 0) {
            val skill = skills.find { it.skillId == originalChef.skill }
            if (skill != null) {
                applyPercentageSkillEffect(chef, skill)
            }
        }
        
        // 2. 处理厨师的修炼技能
        // 检查厨师是否有技法值加成的修炼技能
        val hasTechniqueUltimateSkills = hasTechniqueUltimateSkills(originalChef, skills)
        
        // 如果厨师有技法值加成的修炼技能，需要检查厨师状态
        if (hasTechniqueUltimateSkills) {
            // 检查厨师是否应该应用修炼技能：默认全修炼开启 或 (已拥有且已修炼)
            val shouldApplyUltimateSkills = if (useAllUltimateTraining) {
                true // 默认全修炼时，所有厨师都视为已修炼
            } else {
                originalChef.got && originalChef.ult // 只有已拥有且已修炼的厨师才有修炼技能效果
            }
            
            if (!shouldApplyUltimateSkills) {
                // 厨师不应该应用修炼技能，跳过修炼技能的技法值加成
                return
            }
        }
        
        // 应用修炼技能（如果通过了状态检查）
        for (skillId in originalChef.getAllUltimateSkills()) {
            val skill = skills.find { it.skillId == skillId }
            if (skill != null) {
                applyPercentageSkillEffect(chef, skill)
            }
        }
    }
    
    /**
     * 检查厨师是否有技法值加成的修炼技能
     * @param chef 厨师数据
     * @param skills 技能数据列表
     * @return true表示有技法值加成的修炼技能
     */
    private fun hasTechniqueUltimateSkills(chef: Chef, skills: List<Skill>): Boolean {
        if (!chef.hasUltimateSkill()) {
            return false
        }
        
        for (skillId in chef.getAllUltimateSkills()) {
            val skill = skills.find { it.skillId == skillId }
            if (skill != null) {
                val desc = skill.desc
                // 检查是否包含技法值加成相关的描述
                if (desc.contains("全技法") || 
                    desc.contains("炒技法") || 
                    desc.contains("煮技法") || 
                    desc.contains("切技法") || 
                    desc.contains("炸技法") || 
                    desc.contains("烤技法") || 
                    desc.contains("蒸技法") ||
                    // 添加复合技法的识别
                    desc.matches(Regex(""".*[炒煮切炸烤蒸]与[炒煮切炸烤蒸]技法.*"""))) {
                    return true
                }
            }
        }
        return false
    }
    
    /**
     * 应用单个百分比技能效果
     * @param chef 要应用加成的厨师
     * @param skill 技能数据
     */
    private fun applyPercentageSkillEffect(chef: Chef, skill: Skill) {
        val desc = skill.desc
        
        // 排除非自身技能：全局技能和影响其他厨师的技能
        if (desc.contains("全体") || desc.contains("场上") || desc.contains("上场")) {
            return
        }
        
        // 第一步：处理绝对值加成（先执行）
        // 处理全技法绝对值加成，如"全技法+50"
        if (desc.contains("全技法") && !desc.contains("%")) {
            val absoluteValue = extractAbsoluteValueForSkillType(desc, "全技法")
            if (absoluteValue > 0) {
                chef.stirfry += absoluteValue
                chef.boil += absoluteValue
                chef.knife += absoluteValue
                chef.fry += absoluteValue
                chef.bake += absoluteValue
                chef.steam += absoluteValue
            }
        }
        
        // 处理复合技法绝对值加成，如"炸与炒技法+120"、"煮与蒸技法+80"
        val compoundSkillValue = extractCompoundSkillValue(desc)
        if (compoundSkillValue > 0) {
            val affectedSkills = parseCompoundSkillTypes(desc)
            for (skillType in affectedSkills) {
                when (skillType) {
                    "炒" -> chef.stirfry += compoundSkillValue
                    "煮" -> chef.boil += compoundSkillValue
                    "切" -> chef.knife += compoundSkillValue
                    "炸" -> chef.fry += compoundSkillValue
                    "烤" -> chef.bake += compoundSkillValue
                    "蒸" -> chef.steam += compoundSkillValue
                }
            }
        } else {
            // 处理单项技法绝对值加成（只有在没有复合技法时才处理，避免重复计算）
            val skillTypes = listOf("炒技法", "煮技法", "切技法", "炸技法", "烤技法", "蒸技法")
            for (skillType in skillTypes) {
                if (desc.contains(skillType) && !desc.contains("%")) {
                    val absoluteValue = extractAbsoluteValueForSkillType(desc, skillType)
                    if (absoluteValue > 0) {
                        when (skillType) {
                            "炒技法" -> chef.stirfry += absoluteValue
                            "煮技法" -> chef.boil += absoluteValue
                            "切技法" -> chef.knife += absoluteValue
                            "炸技法" -> chef.fry += absoluteValue
                            "烤技法" -> chef.bake += absoluteValue
                            "蒸技法" -> chef.steam += absoluteValue
                        }
                    }
                }
            }
        }
        
        // 第二步：处理百分比加成（后执行）
        // 处理全技法百分比加成，如"全技法+15%"或"自身菜谱售价+50%且全技法+15%"
        if (desc.contains("全技法") && desc.contains("%")) {
            val percentageValue = extractPercentageValueForSkillType(desc, "全技法")
            if (percentageValue > 0) {
                val multiplier = 1.0 + percentageValue / 100.0
                
                // 对所有技法应用百分比加成，结果向上取整
                chef.stirfry = kotlin.math.ceil(chef.stirfry * multiplier).toInt()
                chef.boil = kotlin.math.ceil(chef.boil * multiplier).toInt()
                chef.knife = kotlin.math.ceil(chef.knife * multiplier).toInt()
                chef.fry = kotlin.math.ceil(chef.fry * multiplier).toInt()
                chef.bake = kotlin.math.ceil(chef.bake * multiplier).toInt()
                chef.steam = kotlin.math.ceil(chef.steam * multiplier).toInt()
            }
        }
        
        // 处理复合技法百分比加成，如"炸与炒技法+20%"
        val compoundSkillPercentage = extractCompoundSkillPercentage(desc)
        if (compoundSkillPercentage > 0) {
            val multiplier = 1.0 + compoundSkillPercentage / 100.0
            val affectedSkills = parseCompoundSkillTypes(desc)
            for (skillType in affectedSkills) {
                when (skillType) {
                    "炒" -> chef.stirfry = kotlin.math.ceil(chef.stirfry * multiplier).toInt()
                    "煮" -> chef.boil = kotlin.math.ceil(chef.boil * multiplier).toInt()
                    "切" -> chef.knife = kotlin.math.ceil(chef.knife * multiplier).toInt()
                    "炸" -> chef.fry = kotlin.math.ceil(chef.fry * multiplier).toInt()
                    "烤" -> chef.bake = kotlin.math.ceil(chef.bake * multiplier).toInt()
                    "蒸" -> chef.steam = kotlin.math.ceil(chef.steam * multiplier).toInt()
                }
            }
        } else {
            // 处理单项技法百分比加成（只有在没有复合技法时才处理）
            val skillTypes = listOf("炒技法", "煮技法", "切技法", "炸技法", "烤技法", "蒸技法")
            for (skillType in skillTypes) {
                if (desc.contains(skillType) && desc.contains("%")) {
                    val percentageValue = extractPercentageValueForSkillType(desc, skillType)
                    if (percentageValue > 0) {
                        val multiplier = 1.0 + percentageValue / 100.0
                        
                        when (skillType) {
                            "炒技法" -> chef.stirfry = kotlin.math.ceil(chef.stirfry * multiplier).toInt()
                            "煮技法" -> chef.boil = kotlin.math.ceil(chef.boil * multiplier).toInt()
                            "切技法" -> chef.knife = kotlin.math.ceil(chef.knife * multiplier).toInt()
                            "炸技法" -> chef.fry = kotlin.math.ceil(chef.fry * multiplier).toInt()
                            "烤技法" -> chef.bake = kotlin.math.ceil(chef.bake * multiplier).toInt()
                            "蒸技法" -> chef.steam = kotlin.math.ceil(chef.steam * multiplier).toInt()
                        }
                    }
                }
            }
        }
        
        // 可以在这里添加其他类型的技能处理
        // 例如：菜谱售价等（这些不影响技法值）
    }
    
        /**
     * 从技能描述中提取特定技能类型的百分比数值
     * 例如："自身菜谱售价+50%且全技法+15%" + "全技法" -> 15
     * 例如："炒技法+20%" + "炒技法" -> 20
     */
    private fun extractPercentageValueForSkillType(desc: String, skillType: String): Int {
        val regex = Regex("""${skillType}\+(\d+)%""")
        val match = regex.find(desc)
        return match?.groupValues?.get(1)?.toIntOrNull() ?: 0
    }

    /**
     * 从技能描述中提取特定技能类型的绝对值
     * 例如："全技法+50" + "全技法" -> 50
     * 例如："炒技法+20" + "炒技法" -> 20
     */
    private fun extractAbsoluteValueForSkillType(desc: String, skillType: String): Int {
        val regex = Regex("""${skillType}\+(\d+)""")
        val match = regex.find(desc)
        return match?.groupValues?.get(1)?.toIntOrNull() ?: 0
    }

    /**
     * 从技能描述中提取复合技能的数值（如"炸与炒技法+120"）
     * 返回复合技能的数值，如果没有则返回0
     */
    private fun extractCompoundSkillValue(desc: String): Int {
        // 匹配"炸与炒技法+120"、"煮与蒸技法+80"等模式
        val regex = Regex("""([炒煮切炸烤蒸])与([炒煮切炸烤蒸])技法\+(\d+)""")
        val match = regex.find(desc)
        return match?.groupValues?.get(3)?.toIntOrNull() ?: 0
    }

    /**
     * 从技能描述中提取复合技能的百分比（如"炸与炒技法+20%"）
     * 返回复合技能的百分比，如果没有则返回0
     */
    private fun extractCompoundSkillPercentage(desc: String): Int {
        // 匹配"炸与炒技法+20%"等模式
        val regex = Regex("""([炒煮切炸烤蒸])与([炒煮切炸烤蒸])技法\+(\d+)%""")
        val match = regex.find(desc)
        return match?.groupValues?.get(3)?.toIntOrNull() ?: 0
    }

    /**
     * 解析技能描述，提取复合技能类型列表（如"炸与炒技法" -> ["炸", "炒"]）
     */
    private fun parseCompoundSkillTypes(desc: String): List<String> {
        val types = mutableListOf<String>()
        // 匹配"炸与炒技法"等模式
        val regex = Regex("""([炒煮切炸烤蒸])与([炒煮切炸烤蒸])技法""")
        val match = regex.find(desc)
        if (match != null) {
            types.add(match.groupValues[1])
            types.add(match.groupValues[2])
        }
        return types
    }

    /**
     * 计算厨师个人技法值
     * @param chef 厨师对象
     * @param isUltimateTrained 修炼状态（true表示已修炼）
     * @param equip 厨具对象（可选）
     * @param redAmber 红色心法盘对象（可选）
     * @param ultimateSkills 个人数据加成
     * @param skills 技能数据列表
     * @param auraChefSkillIds 场上光环厨师技能ID列表（实验室中默认传null）
     * @return 具有计算后技法值的Chef对象
     */
    fun calculateChefPersonalSkills(
        chef: Chef,
        isUltimateTrained: Boolean,
        equipId: String? = null,
        redAmberIds: List<String> = emptyList(),
        redAmberLevel: Int = 1,
        ultimateSkills: UltimateSkillsState = UltimateSkillsState(),
        skills: List<Skill> = emptyList(),
        gameData: GameData? = null,
        auraChefSkillIds: List<Int>? = null
    ): Chef {
        // 添加吕布的调试日志
        if (chef.name == "吕布") {
            println("DEBUG: 吕布 - 开始计算个人技法值")
            println("DEBUG: 吕布 - 修炼状态: $isUltimateTrained")
            println("DEBUG: 吕布 - 基础技法值: 炒${chef.stirfry} 煮${chef.boil} 切${chef.knife} 炸${chef.fry} 烤${chef.bake} 蒸${chef.steam}")
            println("DEBUG: 吕布 - 常驻技能ID: ${chef.skill}")
            println("DEBUG: 吕布 - 修炼技能: ${if (chef.hasUltimateSkill()) chef.getAllUltimateSkills() else "无"}")
            println("DEBUG: 吕布 - 厨具ID: $equipId")
            println("DEBUG: 吕布 - 红色心法盘ID: $redAmberIds")
            println("DEBUG: 吕布 - 红色心法盘等级: $redAmberLevel")
        }
        // 初始化技法值（基础技法值）
        val skillValues = mutableMapOf(
            "stirfry" to chef.stirfry,
            "boil" to chef.boil,
            "knife" to chef.knife,
            "fry" to chef.fry,
            "bake" to chef.bake,
            "steam" to chef.steam
        )

        // 1. 计算固定值加成
        var fixedValueBonus = mutableMapOf(
            "stirfry" to 0,
            "boil" to 0,
            "knife" to 0,
            "fry" to 0,
            "bake" to 0,
            "steam" to 0
        )

        // 1.1 厨师常驻技能固定值加成
        if (chef.skill > 0) {
            val skill = skills.find { it.skillId == chef.skill }
            if (chef.name == "吕布") {
                println("DEBUG: 吕布 - 常驻技能: ${skill?.desc ?: "未找到"}")
                skill?.effect?.forEach { effect ->
                    println("DEBUG: 吕布 - 常驻技能效果: type=${effect.type}, value=${effect.value}, cal=${effect.cal}")
                }
            }
            skill?.effect?.forEach { effect ->
                if (effect.cal == "Abs") {
                    when (effect.type) {
                        "Stirfry" -> fixedValueBonus["stirfry"] = fixedValueBonus["stirfry"]!! + effect.value
                        "Boil" -> fixedValueBonus["boil"] = fixedValueBonus["boil"]!! + effect.value
                        "Knife" -> fixedValueBonus["knife"] = fixedValueBonus["knife"]!! + effect.value
                        "Fry" -> fixedValueBonus["fry"] = fixedValueBonus["fry"]!! + effect.value
                        "Bake" -> fixedValueBonus["bake"] = fixedValueBonus["bake"]!! + effect.value
                        "Steam" -> fixedValueBonus["steam"] = fixedValueBonus["steam"]!! + effect.value
                    }
                }
            }
        }

        // 1.2 修炼技能固定值加成（只有已修炼时才生效）
        if (isUltimateTrained && chef.hasUltimateSkill()) {
            val chefUltimateSkills = chef.getAllUltimateSkills()
            if (chef.name == "吕布") {
                println("DEBUG: 吕布 - 修炼技能数量: ${chefUltimateSkills.size}")
            }
            chefUltimateSkills.forEach { skillId ->
                val skill = skills.find { it.skillId == skillId }
                if (chef.name == "吕布") {
                    println("DEBUG: 吕布 - 修炼技能ID $skillId: ${skill?.desc ?: "未找到"}")
                    skill?.effect?.forEach { effect ->
                        println("DEBUG: 吕布 - 修炼技能效果: type=${effect.type}, value=${effect.value}, cal=${effect.cal}, condition=${effect.condition}")
                    }
                }
                skill?.effect?.forEach { effect ->
                    if (effect.condition == "Self" && effect.cal == "Abs") {
                        when (effect.type) {
                            "Stirfry" -> fixedValueBonus["stirfry"] = fixedValueBonus["stirfry"]!! + effect.value
                            "Boil" -> fixedValueBonus["boil"] = fixedValueBonus["boil"]!! + effect.value
                            "Knife" -> fixedValueBonus["knife"] = fixedValueBonus["knife"]!! + effect.value
                            "Fry" -> fixedValueBonus["fry"] = fixedValueBonus["fry"]!! + effect.value
                            "Bake" -> fixedValueBonus["bake"] = fixedValueBonus["bake"]!! + effect.value
                            "Steam" -> fixedValueBonus["steam"] = fixedValueBonus["steam"]!! + effect.value
                        }
                    }
                }
            }
        }

        // 1.3 厨具技能固定值加成
        if (equipId != null) {
            // 根据厨具ID获取厨具对象
            val equip = gameData?.equips?.find { it.equipId == equipId }
            
            if (equip != null) {
                // 计算厨具技能效果翻倍加成
                var mutiEquipmentSkill = 0
                if (isUltimateTrained && chef.hasUltimateSkill()) {
                    val chefUltimateSkills = chef.getAllUltimateSkills()
                    chefUltimateSkills.forEach { skillId ->
                        val skill = skills.find { it.skillId == skillId }
                        skill?.effect?.forEach { effect ->
                            if (effect.type == "MutiEquipmentSkill" && effect.cal == "Percent") {
                                mutiEquipmentSkill += effect.value
                            }
                        }
                    }
                }

                equip.skill.forEach { skillId ->
                    val skill = skills.find { it.skillId == skillId }
                    skill?.effect?.forEach { effect ->
                        if (effect.cal == "Abs") {
                            val bonusValue = (effect.value * (100 + mutiEquipmentSkill) / 100).toInt()
                            when (effect.type) {
                                "Stirfry" -> fixedValueBonus["stirfry"] = fixedValueBonus["stirfry"]!! + bonusValue
                                "Boil" -> fixedValueBonus["boil"] = fixedValueBonus["boil"]!! + bonusValue
                                "Knife" -> fixedValueBonus["knife"] = fixedValueBonus["knife"]!! + bonusValue
                                "Fry" -> fixedValueBonus["fry"] = fixedValueBonus["fry"]!! + bonusValue
                                "Bake" -> fixedValueBonus["bake"] = fixedValueBonus["bake"]!! + bonusValue
                                "Steam" -> fixedValueBonus["steam"] = fixedValueBonus["steam"]!! + bonusValue
                            }
                        }
                    }
                }
            }
        }

        // 2. 应用固定值加成到技法值
        skillValues.forEach { (skillType, _) ->
            skillValues[skillType] = skillValues[skillType]!! + fixedValueBonus[skillType]!!
        }
        
        // 吕布的固定值加成调试
        if (chef.name == "吕布") {
            println("DEBUG: 吕布 - 固定值加成: 炒${fixedValueBonus["stirfry"]} 煮${fixedValueBonus["boil"]} 切${fixedValueBonus["knife"]} 炸${fixedValueBonus["fry"]} 烤${fixedValueBonus["bake"]} 蒸${fixedValueBonus["steam"]}")
            println("DEBUG: 吕布 - 应用固定值加成后: 炒${skillValues["stirfry"]} 煮${skillValues["boil"]} 切${skillValues["knife"]} 炸${skillValues["fry"]} 烤${skillValues["bake"]} 蒸${skillValues["steam"]}")
        }

        // 3. 应用个人数据加成
        skillValues["stirfry"] = skillValues["stirfry"]!! + ultimateSkills.stirfry
        skillValues["boil"] = skillValues["boil"]!! + ultimateSkills.boil
        skillValues["knife"] = skillValues["knife"]!! + ultimateSkills.knife
        skillValues["fry"] = skillValues["fry"]!! + ultimateSkills.fry
        skillValues["bake"] = skillValues["bake"]!! + ultimateSkills.bake
        skillValues["steam"] = skillValues["steam"]!! + ultimateSkills.steam

        // 4. 应用男女技法值加成
        if (chef.tags.contains(1)) { // 男厨
            skillValues["stirfry"] = skillValues["stirfry"]!! + ultimateSkills.maleAllSkill
            skillValues["boil"] = skillValues["boil"]!! + ultimateSkills.maleAllSkill
            skillValues["knife"] = skillValues["knife"]!! + ultimateSkills.maleAllSkill
            skillValues["fry"] = skillValues["fry"]!! + ultimateSkills.maleAllSkill
            skillValues["bake"] = skillValues["bake"]!! + ultimateSkills.maleAllSkill
            skillValues["steam"] = skillValues["steam"]!! + ultimateSkills.maleAllSkill
        } else if (chef.tags.contains(2)) { // 女厨
            skillValues["stirfry"] = skillValues["stirfry"]!! + ultimateSkills.femaleAllSkill
            skillValues["boil"] = skillValues["boil"]!! + ultimateSkills.femaleAllSkill
            skillValues["knife"] = skillValues["knife"]!! + ultimateSkills.femaleAllSkill
            skillValues["fry"] = skillValues["fry"]!! + ultimateSkills.femaleAllSkill
            skillValues["bake"] = skillValues["bake"]!! + ultimateSkills.femaleAllSkill
            skillValues["steam"] = skillValues["steam"]!! + ultimateSkills.femaleAllSkill
        }

        // 5. 计算百分比加成
        var percentageBonus = mutableMapOf(
            "stirfry" to 0,
            "boil" to 0,
            "knife" to 0,
            "fry" to 0,
            "bake" to 0,
            "steam" to 0
        )

        // 5.1 厨师常驻技能百分比加成
        if (chef.skill > 0) {
            val skill = skills.find { it.skillId == chef.skill }
            skill?.effect?.forEach { effect ->
                if (effect.cal == "Percent") {
                    when (effect.type) {
                        "Stirfry" -> percentageBonus["stirfry"] = percentageBonus["stirfry"]!! + effect.value
                        "Boil" -> percentageBonus["boil"] = percentageBonus["boil"]!! + effect.value
                        "Knife" -> percentageBonus["knife"] = percentageBonus["knife"]!! + effect.value
                        "Fry" -> percentageBonus["fry"] = percentageBonus["fry"]!! + effect.value
                        "Bake" -> percentageBonus["bake"] = percentageBonus["bake"]!! + effect.value
                        "Steam" -> percentageBonus["steam"] = percentageBonus["steam"]!! + effect.value
                    }
                }
            }
        }

        // 5.2 修炼技能百分比加成（只有已修炼时才生效）
        if (isUltimateTrained && chef.hasUltimateSkill()) {
            val chefUltimateSkills = chef.getAllUltimateSkills()
            chefUltimateSkills.forEach { skillId ->
                val skill = skills.find { it.skillId == skillId }
                skill?.effect?.forEach { effect ->
                    if (effect.condition == "Self" && effect.cal == "Percent") {
                        when (effect.type) {
                            "Stirfry" -> percentageBonus["stirfry"] = percentageBonus["stirfry"]!! + effect.value
                            "Boil" -> percentageBonus["boil"] = percentageBonus["boil"]!! + effect.value
                            "Knife" -> percentageBonus["knife"] = percentageBonus["knife"]!! + effect.value
                            "Fry" -> percentageBonus["fry"] = percentageBonus["fry"]!! + effect.value
                            "Bake" -> percentageBonus["bake"] = percentageBonus["bake"]!! + effect.value
                            "Steam" -> percentageBonus["steam"] = percentageBonus["steam"]!! + effect.value
                        }
                    }
                }
            }
        }

        // 5.3 厨具技能百分比加成
        if (equipId != null) {
            // 根据厨具ID获取厨具对象
            val equip = gameData?.equips?.find { it.equipId == equipId }
            
            if (equip != null) {
                // 计算厨具技能效果翻倍加成
                var mutiEquipmentSkill = 0
                if (isUltimateTrained && chef.hasUltimateSkill()) {
                    val chefUltimateSkills = chef.getAllUltimateSkills()
                    chefUltimateSkills.forEach { skillId ->
                        val skill = skills.find { it.skillId == skillId }
                        skill?.effect?.forEach { effect ->
                            if (effect.type == "MutiEquipmentSkill" && effect.cal == "Percent") {
                                mutiEquipmentSkill += effect.value
                            }
                        }
                    }
                }

                equip.skill.forEach { skillId ->
                    val skill = skills.find { it.skillId == skillId }
                    skill?.effect?.forEach { effect ->
                        if (effect.cal == "Percent") {
                            val bonusValue = (effect.value * (100 + mutiEquipmentSkill) / 100).toInt()
                            when (effect.type) {
                                "Stirfry" -> percentageBonus["stirfry"] = percentageBonus["stirfry"]!! + bonusValue
                                "Boil" -> percentageBonus["boil"] = percentageBonus["boil"]!! + bonusValue
                                "Knife" -> percentageBonus["knife"] = percentageBonus["knife"]!! + bonusValue
                                "Fry" -> percentageBonus["fry"] = percentageBonus["fry"]!! + bonusValue
                                "Bake" -> percentageBonus["bake"] = percentageBonus["bake"]!! + bonusValue
                                "Steam" -> percentageBonus["steam"] = percentageBonus["steam"]!! + bonusValue
                            }
                        }
                    }
                }
            }
        }

        // 5.4 红色心法盘百分比加成（考虑等级加成）
        if (redAmberIds.isNotEmpty()) {
            redAmberIds.forEach { amberId ->
                val amber = gameData?.ambers?.find { it.amberId == amberId }
                if (amber != null) {
                    amber.skill.forEach { skillId ->
                        val skill = skills.find { it.skillId == skillId }
                        skill?.effect?.forEach { effect ->
                            if (effect.cal == "Percent") {
                                // 使用amplification字段计算：初始值 + (等级-1) * amplification
                                val adjustedValue = effect.value + (redAmberLevel - 1) * amber.amplification
                                
                                when (effect.type) {
                                    "Stirfry" -> percentageBonus["stirfry"] = percentageBonus["stirfry"]!! + adjustedValue
                                    "Boil" -> percentageBonus["boil"] = percentageBonus["boil"]!! + adjustedValue
                                    "Knife" -> percentageBonus["knife"] = percentageBonus["knife"]!! + adjustedValue
                                    "Fry" -> percentageBonus["fry"] = percentageBonus["fry"]!! + adjustedValue
                                    "Bake" -> percentageBonus["bake"] = percentageBonus["bake"]!! + adjustedValue
                                    "Steam" -> percentageBonus["steam"] = percentageBonus["steam"]!! + adjustedValue
                                }
                                
                                // 吕布的红色心法盘调试
                                if (chef.name == "吕布") {
                                    println("DEBUG: 吕布 - 红色心法盘ID $amberId: ${amber.name}")
                                    println("DEBUG: 吕布 - 红色心法盘技能ID $skillId: ${skill?.desc ?: "未找到"}")
                                    println("DEBUG: 吕布 - 红色心法盘效果: type=${effect.type}, value=${effect.value}, cal=${effect.cal}")
                                    println("DEBUG: 吕布 - 心法盘等级: $redAmberLevel, amplification: ${amber.amplification}, 调整后数值: $adjustedValue")
                                }
                            }
                        }
                    }
                }
            }
        }

        // 5.5 场上光环厨师技能加成
        if (auraChefSkillIds != null) {
            auraChefSkillIds.forEach { skillId ->
                val skill = skills.find { it.skillId == skillId }
                skill?.effect?.forEach { effect ->
                    // 只处理影响场上厨师的技能（condition为"Partial"）
                    if (effect.condition == "Partial") {
                        when (effect.cal) {
                            "Abs" -> {
                                // 绝对值加成
                                when (effect.type) {
                                    "Stirfry" -> fixedValueBonus["stirfry"] = fixedValueBonus["stirfry"]!! + effect.value
                                    "Boil" -> fixedValueBonus["boil"] = fixedValueBonus["boil"]!! + effect.value
                                    "Knife" -> fixedValueBonus["knife"] = fixedValueBonus["knife"]!! + effect.value
                                    "Fry" -> fixedValueBonus["fry"] = fixedValueBonus["fry"]!! + effect.value
                                    "Bake" -> fixedValueBonus["bake"] = fixedValueBonus["bake"]!! + effect.value
                                    "Steam" -> fixedValueBonus["steam"] = fixedValueBonus["steam"]!! + effect.value
                                }
                            }
                            "Percent" -> {
                                // 百分比加成
                                when (effect.type) {
                                    "Stirfry" -> percentageBonus["stirfry"] = percentageBonus["stirfry"]!! + effect.value
                                    "Boil" -> percentageBonus["boil"] = percentageBonus["boil"]!! + effect.value
                                    "Knife" -> percentageBonus["knife"] = percentageBonus["knife"]!! + effect.value
                                    "Fry" -> percentageBonus["fry"] = percentageBonus["fry"]!! + effect.value
                                    "Bake" -> percentageBonus["bake"] = percentageBonus["bake"]!! + effect.value
                                    "Steam" -> percentageBonus["steam"] = percentageBonus["steam"]!! + effect.value
                                }
                            }
                        }
                    }
                }
            }
        }

        // 6. 重新应用光环厨师的固定值加成（因为可能在步骤5.5中有新的固定值加成）
        skillValues.forEach { (skillType, _) ->
            val baseValue = when (skillType) {
                "stirfry" -> chef.stirfry
                "boil" -> chef.boil
                "knife" -> chef.knife
                "fry" -> chef.fry
                "bake" -> chef.bake
                "steam" -> chef.steam
                else -> 0
            }
            val personalValue = when (skillType) {
                "stirfry" -> ultimateSkills.stirfry
                "boil" -> ultimateSkills.boil
                "knife" -> ultimateSkills.knife
                "fry" -> ultimateSkills.fry
                "bake" -> ultimateSkills.bake
                "steam" -> ultimateSkills.steam
                else -> 0
            }
            val genderValue = if (chef.tags.contains(1)) ultimateSkills.maleAllSkill 
                             else if (chef.tags.contains(2)) ultimateSkills.femaleAllSkill 
                             else 0
            
            skillValues[skillType] = baseValue + fixedValueBonus[skillType]!! + personalValue + genderValue
        }

        // 7. 应用百分比加成
        skillValues.forEach { (skillType, currentValue) ->
            val percentage = percentageBonus[skillType]!!
            if (percentage > 0) {
                val bonus = kotlin.math.ceil(currentValue * percentage / 100.0).toInt()
                skillValues[skillType] = currentValue + bonus
            }
        }
        
        // 吕布的最终结果调试
        if (chef.name == "吕布") {
            println("DEBUG: 吕布 - 百分比加成: 炒${percentageBonus["stirfry"]}% 煮${percentageBonus["boil"]}% 切${percentageBonus["knife"]}% 炸${percentageBonus["fry"]}% 烤${percentageBonus["bake"]}% 蒸${percentageBonus["steam"]}%")
            println("DEBUG: 吕布 - 最终技法值: 炒${skillValues["stirfry"]} 煮${skillValues["boil"]} 切${skillValues["knife"]} 炸${skillValues["fry"]} 烤${skillValues["bake"]} 蒸${skillValues["steam"]}")
            println("DEBUG: 吕布 - 计算完成")
        }

        // 8. 创建并返回新的Chef对象，包含计算后的技法值
        return chef.copy(
            stirfry = skillValues["stirfry"]!!,
            boil = skillValues["boil"]!!,
            knife = skillValues["knife"]!!,
            fry = skillValues["fry"]!!,
            bake = skillValues["bake"]!!,
            steam = skillValues["steam"]!!
        )
    }

    /**
     * 应用个人技法加成和厨具技能加成到厨师上 - 新版本使用正确的计算顺序
     * @param chef 原始厨师数据
     * @param ultimateSkills 个人技法加成数据
     * @param equip 厨具数据（可选）
     * @param skills 技能数据列表
     * @param chefInteractionBonus 厨师间技法影响加成（可选）
     * @param gameData 游戏数据（用于获取厨具信息）
     * @return 应用加成后的厨师数据副本
     */
    fun applyAllSkillsV2(
        chef: Chef,
        ultimateSkills: UltimateSkillsState,
        equip: Equip? = null,
        skills: List<Skill> = emptyList(),
        chefInteractionBonus: Map<String, Int>? = null,
        gameData: GameData? = null
    ): Chef {
        // 将光环厨师影响转换为技能ID列表（这里简化处理，实际应该通过设置获取）
        // 注意：这是一个简化的实现，实际的光环厨师技能ID应该从设置中获取
        val auraChefSkillIds: List<Int>? = null // 暂时设为null，保持与原有逻辑一致
        
        return calculateChefPersonalSkills(
            chef = chef,
            isUltimateTrained = chef.ult, // 使用厨师的修炼状态
            equipId = equip?.equipId,
            redAmberIds = emptyList(), // 查询厨师修炼页面不使用心法盘
            redAmberLevel = 1,
            ultimateSkills = ultimateSkills,
            skills = skills,
            gameData = gameData,
            auraChefSkillIds = auraChefSkillIds
        ).let { enhancedChef ->
            // 如果有厨师间技法影响，需要手动应用（因为calculateChefPersonalSkills不直接支持这种格式）
            if (chefInteractionBonus != null) {
                enhancedChef.copy(
                    stirfry = enhancedChef.stirfry + (chefInteractionBonus["stirfry"] ?: 0),
                    boil = enhancedChef.boil + (chefInteractionBonus["boil"] ?: 0),
                    knife = enhancedChef.knife + (chefInteractionBonus["knife"] ?: 0),
                    fry = enhancedChef.fry + (chefInteractionBonus["fry"] ?: 0),
                    bake = enhancedChef.bake + (chefInteractionBonus["bake"] ?: 0),
                    steam = enhancedChef.steam + (chefInteractionBonus["steam"] ?: 0)
                )
            } else {
                enhancedChef
            }
        }
    }
}